import { toJS } from 'mobx';
import { requiredPngImg } from '.';
export default class WeaSelectCellType extends GC.Spread.Sheets.CellTypes.ComboBox {
    fieldType;
    typeName = 'WeaSelectCellType';
    viewAttr = 2;
    label;
    expandType;
    items;
    combineSameCell;
    id;
    multilang;
    fieldVisible;
    paint(ctx, value, x, y, w, h, style, context) {
        if(this.fieldVisible == '1') {
            this.viewAttr = 1;
            return;
        }
        if (!ctx) {
            return;
        }
        if(this.viewAttr != 1) {
            super.paint(ctx, value, x, y, w, h, style, context);
        } else {
            ctx.imageSmoothingEnabled = false;
            super.paint(ctx, value, x, y, w, h, style, context);
            ctx.drawImage(requiredPngImg, x, y, w,w);
        }
        
        if (this.viewAttr == 3) {
            if (value) {
            } else {
                ctx.drawImage(requiredPngImg, x + w - 8, y + (h - 7) / 2, 7, 7);
            }

        }

    }

    fromJSON(setting) {
        this.fieldType = toJS(setting.fieldType);
        this.viewAttr = setting.viewAttr;
        this.fieldVisible = setting.fieldVisible;
        this.label = setting.label;
        this.expandType = setting.expandType;
        this.combineSameCell = setting.combineSameCell;
        this.id = setting.id;
        this.multilang = setting.multilang;
        let childValue = [];
        if (this.fieldType && this.fieldType.length > 2) {
            const { datas = [] } = this.fieldType[2] || {};
            this.items(datas.map((d) => ({ text: d.selectName, value: '' + d.selectValue })));
            this.editorValueType(GC.Spread.Sheets.CellTypes.EditorValueType.value);
            childValue = datas.map((d) => ({ key: d.selectName, showname: d.selectName }));
        }
        return childValue;
    }
    doUpdateValue = (context, value) => {
        context.value(value);
    }
    toJSON = (setting) => {
       let res =  super.toJSON();
       res.viewAttr = this.viewAttr;
       res.fieldVisible = this.fieldVisible;
       res.label = this.label;
       res.expandType = this.expandType;
       res.fieldType = this.fieldType;
       res.combineSameCell = this.combineSameCell;
       res.multilang = this.multilang;
       return res;
    }
}